﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DNEL.Extensions
{
    /// <summary>
    /// 
    /// </summary>
    public static class TreeViewExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tv"></param>
        /// <param name="action"></param>
        public static void Do(this TreeView tv, Action<TreeNode> action)
        {
            foreach (TreeNode node in tv.Nodes)
            {
                DoRecursive(node, action);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tn"></param>
        /// <param name="action"></param>
        private static void DoRecursive(TreeNode tn, Action<TreeNode> action)
        {
            action(tn);

            foreach (TreeNode subNode in tn.Nodes)
            {
                DoRecursive(subNode, action);
            }
        }
    }
}
